package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;

import com.vf.admin.miaodong.entity.VipOrder;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/8/9 21:08
 */
@Repository
public class AfterVipOrderDao extends BaseDao<VipOrder> {

    public List<VipOrder> findList(Map<String, Object> map, SplitPageBean bean) {


        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM vip_order a where 1=1 ");
        if (StringEx.isNotNull(map.get("nick"))) {
            sbStr.append(" and a.nick like ? ");
            paramList.add("%" + map.get("nick") + "%");
        }
        if (StringEx.isNotNull(map.get("phone"))) {
            sbStr.append(" and a.phone = ? ");
            paramList.add(map.get("phone"));
        }
        if (StringEx.isNotNull(map.get("type"))) {
            sbStr.append(" and a.type = ? ");
            paramList.add(map.get("type"));
        }
        if (StringEx.isNotNull(map.get("status"))) {
            sbStr.append(" and a.status = ? ");
            paramList.add(map.get("status"));
        }
        if (StringEx.isNotNull(map.get("orderno"))) {
            sbStr.append(" and a.orderno = ? ");
            paramList.add(map.get("orderno"));
        }
        if (!StringEx.isNull(map.get("startdate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(map.get("startdate"));
        }
        if (!StringEx.isNull(map.get("enddate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(map.get("enddate"));
        }
        if (!StringEx.isNull(map.get("orderNo"))) {
            sbStr.append(" and a.orderNo = ? ");
            paramList.add(map.get("orderNo"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class, bean);
    }

    public List<VipOrder> total(Map<String, Object> params) {

        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from vip_order where 1=1 ");
        sbStr.append(" and status = 1 ");
//        if(params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
//            sbStr.append(" and to_days(createTime) = to_days(now())");
//        }
        if (params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("today") + "%");
        }
        if (params.containsKey("alltoday") && StringEx.isNotNull(params.get("alltoday"))) {
            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("alltoday"));
        }
        sbStr.append(" and vipPackageId not in (1000,4)");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class);
    }

    public List<VipOrder> list(Map<String, Object> params) {

        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from vip_order where 1=1 ");
        sbStr.append(" and status = 1 ");
        if (params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("today") + "%");
        }
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class);
    }

    public List<VipOrder> todayMengPiao(Map<String, Object> params) {

        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from vip_order where 1=1 ");
        sbStr.append(" and status = 1 ");
//        if(params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
//            sbStr.append(" and to_days(createTime) = to_days(now())");
//        }
        if (params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("today") + "%");
        }
        if (params.containsKey("alltoday") && StringEx.isNotNull(params.get("alltoday"))) {
            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("alltoday"));
        }
        sbStr.append(" and vipPackageId in (1000,4)");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class);
    }

    public List<VipOrder> getVipOrderTicketV2(Map<String, Object> params) {

        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from vip_order where 1=1 ");
        //默认已支付
        sbStr.append(" and status = 1 ");
        //今日
        if (params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("today") + "%");
        }
        //本月
        if (params.containsKey("month") && StringEx.isNotNull(params.get("month"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("month") + "%");
        }
        //总的
        if (params.containsKey("all") && StringEx.isNotNull(params.get("all"))) {
            sbStr.append(" and createtime <= ?  ");
            paramList.add(params.get("all"));
        }

        //客服 时间区间查询
        if (StringEx.isNotNull(params.get("todayStartTime")) && StringEx.isNotNull(params.get("todayEndTime")) && params.size()==2) {
            sbStr.append(" and createtime >= ? ");
            paramList.add(params.get("todayStartTime"));

            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("todayEndTime"));

        }

        //客服 时间区间查询
        if (StringEx.isNotNull(params.get("todayStartTime1")) && StringEx.isNotNull(params.get("todayEndTime1")) && params.size()==4) {
            sbStr.append("and ( createtime >= ? ");
            paramList.add(params.get("todayStartTime"));

            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("todayEndTime"));


            sbStr.append(" or createtime >= ? ");
            paramList.add(params.get("todayStartTime1"));

            sbStr.append(" and createtime <= ? )");
            paramList.add(params.get("todayEndTime1"));


        }


        //锁定门票
        sbStr.append(" and vipPackageId in (1000,4)");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class);
    }

    public List<VipOrder> getVipOrderV2(Map<String, Object> params) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from vip_order where 1=1 ");
        //默认已支付
        sbStr.append(" and status = 1 ");
        //今日
        if (params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("today") + "%");
        }
        //本月
        if (params.containsKey("month") && StringEx.isNotNull(params.get("month"))) {
            sbStr.append(" and createtime like ? ");
            paramList.add("%" + params.get("month") + "%");
        }
        //总的
        if (params.containsKey("all") && StringEx.isNotNull(params.get("all"))) {
            sbStr.append(" and createtime <= ?  ");
            paramList.add(params.get("all"));
        }

        //客服 时间区间查询
        if (StringEx.isNotNull(params.get("todayStartTime")) && StringEx.isNotNull(params.get("todayEndTime")) && params.size()==2) {
            sbStr.append(" and createtime >= ? ");
            paramList.add(params.get("todayStartTime"));

            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("todayEndTime"));

        }

        //客服 时间区间查询
        if (StringEx.isNotNull(params.get("todayStartTime1")) && StringEx.isNotNull(params.get("todayEndTime1")) && params.size()==4) {
            sbStr.append("and ( createtime >= ? ");
            paramList.add(params.get("todayStartTime"));

            sbStr.append(" and createtime <= ? ");
            paramList.add(params.get("todayEndTime"));


            sbStr.append(" or createtime >= ? ");
            paramList.add(params.get("todayStartTime1"));

            sbStr.append(" and createtime <= ? )");
            paramList.add(params.get("todayEndTime1"));


        }


        //锁定门票
        sbStr.append(" and vipPackageId not in (1000,4)");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, VipOrder.class);
    }
}
